package com.ja.openchat.views;

import android.content.Context;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.ja.openchat.R;
import com.zy.openchat.core.model.user.UserInfo;
import com.ja.openchat.ui.chat.listener.OnContactSendListener;
import com.lxj.xpopup.XPopup;
import com.lxj.xpopup.core.CenterPopupView;

import org.jetbrains.annotations.NotNull;

public class PostContactDialog extends CenterPopupView implements View.OnClickListener{

    public static void show(Context context, UserInfo userInfo, OnContactSendListener listener){
        new XPopup.Builder(context).autoDismiss(true).asCustom(new PostContactDialog(context,userInfo,listener)).show();
    }

    private UserInfo userInfo;
    private OnContactSendListener listener;

    public PostContactDialog(@NonNull @NotNull Context context, UserInfo userInfo, OnContactSendListener listener) {
        super(context);
        this.userInfo = userInfo;
        this.listener = listener;
    }

    @Override
    protected int getImplLayoutId() {
        return R.layout.dialog_post_contact;
    }
    private  EditText message_text;
    @Override
    protected void onCreate() {
        super.onCreate();
        UserAvatarView user_image = findViewById(R.id.user_image);
        TextView user_name = findViewById(R.id.user_name);
        TextView user_name_intro = findViewById(R.id.user_name_intro);
        message_text = findViewById(R.id.message_text);
        findViewById(R.id.cancle_btn).setOnClickListener(this);
        findViewById(R.id.ok_btn).setOnClickListener(this);
        if(userInfo!=null){
            user_image.showUser(userInfo);
            user_name.setText(userInfo.displayName());
            user_name_intro.setText(String.format("[个人名片]%s",userInfo.displayName()));
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.cancle_btn:
                dismiss();
                break;
            case R.id.ok_btn:
                listener.toSend(message_text.getText().toString());
                dismiss();
                break;
        }
    }
}
